<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f ="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      >

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        ShopCar类实例
    </head>
    <body>
        <!-- 我的购物车 -->

        <c:if test="#{sessionScope.myCar==null}">
            <c:set var="myCar" scope="session" value="#{myCar}"/>
        </c:if>
        <c:set var="buylist" value="#{myCar.buylist}"/>
        <c:set var="total" value="0.0"/>
        
      
      
      <table border="1" width="450" rules="none" cellspacing="0" cellpadding="0">
      <tr height="50"><td colspan="7" align="center">购买的商品如下</td></tr>
      <tr align="center" height="30" bgcolor="lightgrey">
      <td>图片</td>
      <td width="25%">名称</td>
      <td>价格(元/斤)</td>
      <td>数量</td>
      <td>总价(元)</td>
      <td>增加(+1/次)</td>
      <td>移除(-1/次)</td>
      </tr>
      
      <c:choose>
          <c:when test="#{buylist == null || buylist.isEmpty()}">
              <tr height="100"><td colspan="7" align="center">您的购物车为空！</td></tr>
          </c:when>
          <c:otherwise>
              <c:forEach var="i" begin="0" end="#{buylist.size() - 1}">
                  <c:set var="single" value="#{buylist.get(i)}"/>
                  <c:set var="name" value="#{single.name}"/>
                  <c:set var="price" value="#{single.price}"/>
                  <c:set var="num" value="#{single.num}"/>
                  <c:set var="url" value="#{single.imgurl}"/>
                  <c:set var="total" value="#{total + (((price*num+0.05)*10))/10.0}" />
                  <tr align="center" height="50">
                    <td><img style='width:50px;' src='#{url}' /></td>
                    <td>
                        #{name}
                    </td>
                    <td>
                        #{price}
                    </td>
                    <td>
                        #{num}
                    
                    </td>
                    <td>
                        #{money}
                  
                    </td>
                    <td>
                    <a href="Docar?action=add2&amp;name=#{mytool.encode(name)}" >
                        增加
                    </a>
                    </td>
                    <td>
                    <a href="Docar?action=remove&amp;name=#{mytool.encode(name)}" >减少</a>
                    </td>
                    </tr>
              </c:forEach>
          </c:otherwise>
      </c:choose>
      <tr height="50" align="center"><td colspan="7">应付金额：
            <h:outputText value="#{total}" >
                <f:convertNumber pattern="#0.0"/>
            </h:outputText>


         <!--<fmt:formatNumber type="number" maxFractionDigits="1" value="#{total}" />-->

      </td></tr>
      <tr height="50" align="center">
      <td colspan="3"><a href="Show.xhtml">继续购物</a></td>
      <td colspan="4"><a href="Docar?action=clear">清空购物车</a></td>
      </tr>
      </table>
      </body>
      </html>
    